//
//  PersonalBlockCell.m
//  ChatForHot
//
//  Created by wr on 2018/10/17.
//  Copyright © 2018年 FLY. All rights reserved.
//

#import "PersonalBlockCell.h"

@interface PersonalBlockCell ()

@property (nonatomic, strong) UIImageView *HOTCHATavatarView;
@property (nonatomic, strong) UILabel *HOTCHATNickNameLable;
@property (nonatomic, strong) UIImageView *HOTCHATlineview;
@property (nonatomic, strong) UIButton *HOTCHATdeleteButton;
@end

@implementation PersonalBlockCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.selectedBackgroundView = [[UIView alloc] init];
        self.selectedBackgroundView.backgroundColor = HOTCHATrgb(242, 242, 242);
        [self HOTCHATdidInitialized];
    }
    return self;
}

- (void)HOTCHATdidInitialized {
    @weakify(self)
    
    self.HOTCHATavatarView = [[UIImageView alloc] init];
    self.HOTCHATavatarView.layer.cornerRadius = 22.5;
    self.HOTCHATavatarView.clipsToBounds = YES;
    self.HOTCHATavatarView.contentMode = UIViewContentModeScaleAspectFill;
    [self.contentView addSubview:self.HOTCHATavatarView];
    
    self.HOTCHATNickNameLable = [[UILabel alloc] init];
    self.HOTCHATNickNameLable.font = [UIFont systemFontOfSize:16];
    self.HOTCHATNickNameLable.textColor = HOTCHATrgb(102,102,102);
    [self.contentView addSubview:self.HOTCHATNickNameLable];
    
    self.HOTCHATdeleteButton = [[UIButton alloc] init];
    [self.HOTCHATdeleteButton setImage:[UIImage imageNamed:@"personal_deleteblock_nor"] forState:(UIControlStateNormal)];
    [self.HOTCHATdeleteButton setImage:[UIImage imageNamed:@"personal_deleteblock_hig"] forState:(UIControlStateHighlighted)];
    [[self.HOTCHATdeleteButton rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(id x) {
        @strongify(self)
        if (self.delegate && [self.delegate respondsToSelector:@selector(HOTCHATDeleteBlockCell:atIndex:)]) {
            [self.delegate HOTCHATDeleteBlockCell:self.model atIndex:self.HOTCHATIndexPath];
        }
    }];
    [self.contentView addSubview:self.HOTCHATdeleteButton];
    
    self.HOTCHATlineview = [[UIImageView alloc] init];
    self.HOTCHATlineview.backgroundColor = HOTCHATrgb(230, 230, 230);
    [self.contentView addSubview:self.HOTCHATlineview];
}

- (void)bind:(UserInfoModel *)model {
    _model = model;
    
    [self.HOTCHATavatarView sd_setImageWithURL:[NSURL URLWithString:[model.headPic HOTCHATTotalStringUrl]] placeholderImage:[UIImage imageNamed:@"photo_selfback_imag"]];
    self.HOTCHATNickNameLable.text = model.nickName;
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    [self.HOTCHATavatarView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.width.height.mas_equalTo(45);
        make.top.left.equalTo(self.contentView).offset(10);
    }];
    [self.HOTCHATNickNameLable mas_updateConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.HOTCHATavatarView.mas_right).offset(10);
        make.centerY.equalTo(self.HOTCHATavatarView);
        make.right.lessThanOrEqualTo(self.contentView).offset(-15);
    }];
    [self.HOTCHATlineview mas_updateConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.equalTo(self.contentView);
        make.height.mas_equalTo(0.5);
    }];
    [self.HOTCHATdeleteButton mas_updateConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.right.equalTo(self.contentView);
        make.width.mas_equalTo(44);
    }];
}
@end
